//导入模块
const express = require('express');
const db = require('../uilit/mysql')


//创建路由
const router = express.Router();

//接口编写
// 获取数据库中resume表的数据 渲染到前端页面中
router.post('/selectResume', (req, res) => {
  const sql = `select * from resume where res_id='2'`;
  db.query(sql, (err, data) => {
    if (err) {
      console.log(err);
    } else {
      console.log( data);
      res.send({ resume: data });
    }
  })
});

router.post('/selectseeker', (req, res) => {
  console.log(1);
  const sql1 = `select * from seeker where s_id='2'`;
  db.query(sql1, (err, data) => {
    if (err) {
      console.log(err);
    } else {
      console.log(1);
      res.send({ seeker: data });
    }
  })
});

router.post('/selectAddress', (req, res) => {
  const sqlpro = `select * from province`;
  const sqlcity = `select * from city`;
  const sqlarea = `select * from area`;
  db.query(sqlpro, (err1, data1) => {
    if (err1) {
      console.log(err1);
    } else {
      db.query(sqlcity, (err2, data2) => {
        if (err2) {
          console.log(err2);
        } else {
          db.query(sqlarea, (err3, data3) => {
            if (err3) {
              console.log(err3);
            } else {
              res.send({ province: data1, city: data2, area: data3 });
            }
          })
        }
      })
    }
  })
});

// 获取前端传递的个人信息数据，将数据保存在求职者表中
router.post('/addseeker1', (req, res) => {
  if(req.body.sex==undefined){
    req.body.sex='男'
  }
  let sqladdseeker = `update seeker set s_name='${req.body.name}',s_sex='${req.body.sex}',
                    s_birth='${req.body.birth}',s_edu='${req.body.edu}',
                    s_phone='${req.body.tel}',s_email='${req.body.email}' 
                    where s_id=2`;
  db.query(sqladdseeker, (err) => {
    if (err) {
      console.log(err);
    } else {
      res.send({ code: res.statusCode });
    }
  });
});
// 获取前端传递的简历数据，将数据保存在简历表中
router.post('/addresume1', (req, res) => {
  let indId;
  let sqlIndId = `select ind_id from industry_category where ind_name='${req.body.industry}';`;
  db.query(sqlIndId, (err, data) => {
    if (err) {
      console.log(err);
    } else {
      // indId = data[0].ind_id;
      let sqladdresume = `insert into resume values(NULL,2,'${req.body.job}',1,'','','',
              '${req.body.jobYear}','${req.body.money}','${req.body.expectCity}','${req.body.jobType}',
              '${req.body.date}','${req.body.jobStatus}');`;
      db.query(sqladdresume, (err) => {
        if (err) {
          console.log(err);
        } else {
          res.send({ code: res.statusCode });
        }
      });
    }
  });
});

module.exports = router;


